package day4.teacher;

/**
 * @author oldliu
 * @since 1.0
 */
public abstract class Teacher implements Comparable<Teacher>{
    private String name;
    private int age;
    public Teacher(){

    }
    public Teacher(String n, int a) {
        this.name = n;
        this.age = a;
    }

    public void selfIntro() {
        System.out.println("我叫" + name + "，今年" + age + "岁了");
    }

    //    public void giveLession(){
//        System.out.println("上课。。。");
//        System.out.println("上完了布置作业");
//    }
    public abstract  void giveLession();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "这是一个老师，名叫" + name + ",年龄是" + age + "岁";
    }

    @Override
    public int hashCode() {
        return this.name==null?0:this.name.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if(obj==null)
            return false;
        if(this==obj)
            return true;
        if(obj instanceof Teacher==false)
            return false;
        Teacher t=(Teacher)obj;
        //用名字来比较，名字相同，对象相同
        if(this.name==null && t.name==null)
            return true;
        if(this.name!=null)
            return this.name.equals(t.name);
        return false;
    }

    @Override
    public int compareTo(Teacher o) {
        //return this.name.compareTo(o.name);
        return this.age-o.age;
    }
}
